

// 是否为空
function isEmpty(obj) {
  if (typeof (obj) == "undefined" || (!obj && typeof (obj) != "undefined" && obj != 0)) {
    return true;
  }
  for (let i in obj) {
    return false;
  }
  return true;
}
// 提示错误信息
function showError(title) {
  var app = getApp();
  wx.showToast({
    title: title,
    // icon: 'success',
    image: '../../images/icon-warn.png',    
    duration: 1500
  })
}

// 提示信息
function showStatus(title) {
  var app = getApp();
  wx.showToast({
    title: title,
    // icon: 'success',
    duration: 1500
  })
}

// 加载中..
function showLoading(loading) {
  wx.showLoading({
    title: loading,
  })
}
// 取消加载中..
function hiddenLoading() {
  wx.hideLoading()
}

// 验证手机号
function validateMobile(mobile) {

  if (this.isEmpty(mobile)) {
    return false;
  }

  if (mobile.length == 0) {
    return false;
  }
  if (mobile.length != 11) {
    return false;
  }
  var reg = /^1[3|4|5|7|8][0-9]{9}$/;
  if (!reg.test(mobile)) {
    return false;
  }
  return true;
}


//验证邮箱
function validateEmail(email) {

  if (this.isEmpty(email)) {
    return false;
  }

  if (email.length == 0) {
    return false;
  }

  var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/;
  if (!reg.test(email)) {
    return false;
  }
  return true;
}

// 验证银行卡号
  function checkBankNo(bankno) {
      var bankno = bankno.replace(/\s/g, '');
      
     if (bankno.length < 15 || bankno.length > 19) {
         return false;
     }
     var num = /^\d*$/;// 全数字
     if (!num.exec(bankno)) {
         return false;
     }
     // 开头两位
     var strBin = "10,12,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
     if (strBin.indexOf(bankno.substring(0, 2)) == -1) {
         return false;
     }
     // luhn校验
    //  if (!luhnCheck(bankno)) {
    //      return false;
    //  }
     return true;
 }

module.exports = {
  isEmpty: isEmpty,
  showError: showError,
  hiddenLoading: hiddenLoading,
  showLoading: showLoading,
  validateMobile: validateMobile,
  showStatus: showStatus,
  validateEmail: validateEmail,
  checkBankNo: checkBankNo
}